package com.ruoyi.project.system.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.Demo;
import com.ruoyi.project.system.service.IDemoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * demoController
 * 
 * @author ruoyi
 * @date 2020-02-17
 */
@RestController
@RequestMapping("/system/demo")
public class DemoController extends BaseController
{
    @Autowired
    private IDemoService demoService;

    /**
     * 查询demo列表
     */
    @PreAuthorize("@ss.hasPermi('system:demo:list')")
    @GetMapping("/list")
    public TableDataInfo list(Demo demo)
    {
        startPage();
        List<Demo> list = demoService.selectDemoList(demo);
        return getDataTable(list);
    }

    /**
     * 导出demo列表
     */
    @PreAuthorize("@ss.hasPermi('system:demo:export')")
    @Log(title = "demo", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Demo demo)
    {
        List<Demo> list = demoService.selectDemoList(demo);
        ExcelUtil<Demo> util = new ExcelUtil<Demo>(Demo.class);
        return util.exportExcel(list, "demo");
    }

    /**
     * 获取demo详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:demo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(demoService.selectDemoById(id));
    }

    /**
     * 新增demo
     */
    @PreAuthorize("@ss.hasPermi('system:demo:add')")
    @Log(title = "demo", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Demo demo)
    {
        return toAjax(demoService.insertDemo(demo));
    }

    /**
     * 修改demo
     */
    @PreAuthorize("@ss.hasPermi('system:demo:edit')")
    @Log(title = "demo", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Demo demo)
    {
        return toAjax(demoService.updateDemo(demo));
    }

    /**
     * 删除demo
     */
    @PreAuthorize("@ss.hasPermi('system:demo:remove')")
    @Log(title = "demo", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(demoService.deleteDemoByIds(ids));
    }
}
